﻿using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbDimensionRecomputePE : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbDimensionRecomputePE(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbDimensionRecomputePE_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbDimensionRecomputePE obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbDimensionRecomputePE()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbDimensionRecomputePE(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public OdDbDimensionRecomputePE() : this(TD_DbPINVOKE.new_OdDbDimensionRecomputePE(), MemoryManager.GetMemoryManager().GetCurrentTransaction() == null)
		{
			MemoryTransaction currentTransaction = MemoryManager.GetMemoryManager().GetCurrentTransaction();
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbDimensionRecomputePE(this.swigCPtr.Handle, true));
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			this.SwigDirectorConnect();
		}

		public static void setMeasurementValue(OdDbDimension pDimension, double measurementValue)
		{
			TD_DbPINVOKE.OdDbDimensionRecomputePE_setMeasurementValue(OdDbDimension.getCPtr(pDimension), measurementValue);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static void resetDimBlockInsertParams(OdDbDimension pDimension)
		{
			TD_DbPINVOKE.OdDbDimensionRecomputePE_resetDimBlockInsertParams(OdDbDimension.getCPtr(pDimension));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new static OdDbDimensionRecomputePE cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbDimensionRecomputePE_cast(OdRxObject.getCPtr(pObj));
			OdDbDimensionRecomputePE result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbDimensionRecomputePE)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbDimensionRecomputePE)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbDimensionRecomputePE)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbDimensionRecomputePE_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(this.SwigDerivedClassHasMethod("isA", OdDbDimensionRecomputePE.swigMethodTypes1) ? TD_DbPINVOKE.OdDbDimensionRecomputePE_isASwigExplicitOdDbDimensionRecomputePE(this.swigCPtr) : TD_DbPINVOKE.OdDbDimensionRecomputePE_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(this.SwigDerivedClassHasMethod("queryX", OdDbDimensionRecomputePE.swigMethodTypes0) ? TD_DbPINVOKE.OdDbDimensionRecomputePE_queryXSwigExplicitOdDbDimensionRecomputePE(this.swigCPtr, OdRxClass.getCPtr(protocolClass)) : TD_DbPINVOKE.OdDbDimensionRecomputePE_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbDimensionRecomputePE createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbDimensionRecomputePE_createObject();
			OdDbDimensionRecomputePE result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbDimensionRecomputePE)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbDimensionRecomputePE)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbDimensionRecomputePE)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void recomputeDimMeasurement(OdDbDimension pDimension)
		{
			TD_DbPINVOKE.OdDbDimensionRecomputePE_recomputeDimMeasurement(this.swigCPtr, OdDbDimension.getCPtr(pDimension));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void recomputeDimBlock(OdDbDimension pDimension, OdDbDimensionObjectContextData ctx)
		{
			TD_DbPINVOKE.OdDbDimensionRecomputePE_recomputeDimBlock(this.swigCPtr, OdDbDimension.getCPtr(pDimension), OdDbDimensionObjectContextData.getCPtr(ctx));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void formatMeasurement(OdDbDimension pDimension, ref string formattedMeasurement, double measurementValue, string dimensionText)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(formattedMeasurement);
			IntPtr value = intPtr;
			try
			{
				TD_DbPINVOKE.OdDbDimensionRecomputePE_formatMeasurement(this.swigCPtr, OdDbDimension.getCPtr(pDimension), ref intPtr, measurementValue, dimensionText);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
			}
			finally
			{
				if (intPtr != value)
				{
					formattedMeasurement = Marshal.PtrToStringUni(intPtr);
				}
			}
		}

		private void SwigDirectorConnect()
		{
			if (this.SwigDerivedClassHasMethod("queryX", OdDbDimensionRecomputePE.swigMethodTypes0))
			{
				this.swigDelegate0 = new OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_0(this.SwigDirectorqueryX);
			}
			if (this.SwigDerivedClassHasMethod("isA", OdDbDimensionRecomputePE.swigMethodTypes1))
			{
				this.swigDelegate1 = new OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_1(this.SwigDirectorisA);
			}
			if (this.SwigDerivedClassHasMethod("recomputeDimMeasurement", OdDbDimensionRecomputePE.swigMethodTypes2))
			{
				this.swigDelegate2 = new OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_2(this.SwigDirectorrecomputeDimMeasurement);
			}
			if (this.SwigDerivedClassHasMethod("recomputeDimBlock", OdDbDimensionRecomputePE.swigMethodTypes3))
			{
				this.swigDelegate3 = new OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_3(this.SwigDirectorrecomputeDimBlock);
			}
			if (this.SwigDerivedClassHasMethod("formatMeasurement", OdDbDimensionRecomputePE.swigMethodTypes4))
			{
				this.swigDelegate4 = new OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_4(this.SwigDirectorformatMeasurement);
			}
			TD_DbPINVOKE.OdDbDimensionRecomputePE_director_connect(this.swigCPtr, this.swigDelegate0, this.swigDelegate1, this.swigDelegate2, this.swigDelegate3, this.swigDelegate4);
		}

		private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes)
		{
			MethodInfo method = base.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, methodTypes, null);
			return method.DeclaringType.IsSubclassOf(typeof(OdDbDimensionRecomputePE));
		}

		private IntPtr SwigDirectorqueryX(IntPtr protocolClass)
		{
			return OdRxObject.getCPtr(this.queryX((OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(protocolClass, false))).Handle;
		}

		private IntPtr SwigDirectorisA()
		{
			return OdRxClass.getCPtr(this.isA()).Handle;
		}

		private void SwigDirectorrecomputeDimMeasurement(IntPtr pDimension)
		{
			this.recomputeDimMeasurement((OdDbDimension)Teigha.Core.Helpers.odrxCreateObjectInternal(pDimension, false));
		}

		private void SwigDirectorrecomputeDimBlock(IntPtr pDimension, IntPtr ctx)
		{
			this.recomputeDimBlock((OdDbDimension)Teigha.Core.Helpers.odrxCreateObjectInternal(pDimension, false), (OdDbDimensionObjectContextData)Teigha.Core.Helpers.odrxCreateObjectInternal(ctx, false));
		}

		private void SwigDirectorformatMeasurement(IntPtr pDimension, ref IntPtr formattedMeasurement, double measurementValue, [MarshalAs(UnmanagedType.LPWStr)] string dimensionText)
		{
			string text = Marshal.PtrToStringUni(formattedMeasurement);
			string b = text;
			try
			{
				this.formatMeasurement((OdDbDimension)Teigha.Core.Helpers.odrxCreateObjectInternal(pDimension, false), ref text, measurementValue, dimensionText);
			}
			finally
			{
				if (text != b)
				{
					formattedMeasurement = Marshal.StringToCoTaskMemUni(text);
				}
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		private OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_0 swigDelegate0;

		private OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_1 swigDelegate1;

		private OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_2 swigDelegate2;

		private OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_3 swigDelegate3;

		private OdDbDimensionRecomputePE.SwigDelegateOdDbDimensionRecomputePE_4 swigDelegate4;

		private static Type[] swigMethodTypes0 = new Type[]
		{
			typeof(OdRxClass)
		};

		private static Type[] swigMethodTypes1 = new Type[0];

		private static Type[] swigMethodTypes2 = new Type[]
		{
			typeof(OdDbDimension)
		};

		private static Type[] swigMethodTypes3 = new Type[]
		{
			typeof(OdDbDimension),
			typeof(OdDbDimensionObjectContextData)
		};

		private static Type[] swigMethodTypes4 = new Type[]
		{
			typeof(OdDbDimension),
			typeof(string).MakeByRefType(),
			typeof(double),
			typeof(string)
		};

		public delegate IntPtr SwigDelegateOdDbDimensionRecomputePE_0(IntPtr protocolClass);

		public delegate IntPtr SwigDelegateOdDbDimensionRecomputePE_1();

		public delegate void SwigDelegateOdDbDimensionRecomputePE_2(IntPtr pDimension);

		public delegate void SwigDelegateOdDbDimensionRecomputePE_3(IntPtr pDimension, IntPtr ctx);

		public delegate void SwigDelegateOdDbDimensionRecomputePE_4(IntPtr pDimension, ref IntPtr formattedMeasurement, double measurementValue, [MarshalAs(UnmanagedType.LPWStr)] string dimensionText);
	}
}
